﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatTrangThai : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaTrangThai();

            layTenTrangThai();
        }
    }

    protected void layMaTrangThai()
    {
        string maTrangThaiURL = Request.QueryString["MaTrangThai"];

        TrangThaiBUS ttBUS = new TrangThaiBUS();

        string maTrangThai = ttBUS.layMaTrangThai(maTrangThaiURL);

        txtMaTrangThai.Text = maTrangThai;
    }

    protected void layTenTrangThai()
    {
        string maTrangThaiURL = Request.QueryString["MaTrangThai"];

        TrangThaiBUS ttbBUS = new TrangThaiBUS();

        string tenTrangThai = ttbBUS.layTenTrangThai(maTrangThaiURL);

        txtTenTrangThai.Text = tenTrangThai;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            TrangThai ttDTO = new TrangThai();
            ttDTO.MaTrangThai = txtMaTrangThai.Text.ToUpper();
            ttDTO.TenTrangThai = txtTenTrangThai.Text.ToUpper();

            //Kiem tra rong
            if (ttDTO.MaTrangThai.ToString() == string.Empty)
            {
                Alert.Show("Ma trang thai khong duoc rong");
                return;
            }

            if (ttDTO.TenTrangThai.ToString() == string.Empty)
            {
                Alert.Show("Ten trang thai khong duoc rong");
                return;
            }

            //Sua
            if (ttDTO.MaTrangThai.ToString() != string.Empty && ttDTO.TenTrangThai.ToString() != string.Empty)
            {
                TrangThaiBUS ttBUS = new TrangThaiBUS();

                string maTrangThaiURL = Request.QueryString["MaTrangThai"];

                ttBUS.suaTrangThai(ttDTO, maTrangThaiURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}